import axios from "axios";
import qs from "qs";
import {createAxios} from '@/axios/axiosInstance'
import interceptors from '@/axios/axios-interceptors'

axios.defaults.timeout = 3000
axios.defaults.responseType = 'json'
axios.defaults.transformRequest = [function (data){
  console.log(data)
  data = {message: '被修改了'}
  if(data instanceof FormData) return data
  data = qs.stringify(data)
  return data;
}]

//服务请求路径前缀

// const {
//   VUE_APP_SERVICE_PROXY_URL: SERVICE_PROXY_URL,
//   VUE_APP_SERVICE_API_PREFIX: SERVICE_API_PREFIX,
//   VUE_APP_UPLOAD_PROXY_URL: UPLOAD_PROXY_URL,
//   VUE_APP_UPLOAD_API_PREFIX: UPLOAD_API_PREFIX,
//   VUE_APP_VERTIFY_PROXY_URL: VERTIFY_PROXY_URL,
//   VUE_APP_VERTIFY_API_PREFIX: VERTIFY_API_PREFIX
// } = process.env

// SERVICE_PROXY_URL 请求路径
// export const $BASE_URL = '/' + SERVICE_PROXY_URL + '/' + SERVICE_API_PREFIX

// export const $VERTIFY_URL = '/' + VERTIFY_PROXY_URL + '/' + VERTIFY_API_PREFIX

// export const $UPLOAD_URL = '/' + UPLOAD_PROXY_URL + '/'

const $BASE_URL = 'https://jsonplaceholder.typicode.com/'
export const httpRequest = createAxios({
  config: {baseURL: $BASE_URL},
  interceptors,
  requestMethods: ['get', 'post', 'put', 'delete', 'upload']
})

// export const httpVertify = createAxios({
//   config: {baseURL: $VERTIFY_URL},
//   interceptors,
//   requestMethods: ['get']
// })
//
// export const httpUpload = createAxios({
//   config: {baseURL: $UPLOAD_URL},
//   interceptors,
//   requestMethods: ['upload']
// })

export default {
  httpRequest
}
